package com.sufen.seckill.study.LeetCode;

import com.sufen.seckill.study.LeetCodeHelper.ListNode;
import org.hibernate.validator.internal.engine.constraintvalidation.PredefinedScopeConstraintValidatorManagerImpl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Author sufen
 * @Date 2021/11/4 16:11
 * @Version 1.0
 * 功能描述：
 */
public class Offer_06_从尾到头打印链表 {
    public static void main(String[] args) {
        ListNode head=new ListNode(1);
        ListNode next2=new ListNode(2);
        ListNode next3=new ListNode(3);
        ListNode next4=new ListNode(4);
        head.next=next2;
        next2.next=next3;
        next3.next=next4;
        int[] res=reversePrint(head);
        for(int tmp:res){
            System.out.print(tmp);
        }
    }
    public static int[] reversePrint(ListNode head) {
        List<Integer> list=new ArrayList<>();

        ListNode cur=head;

        while(cur!=null){
            int tmp=cur.val;
            list.add(tmp);
            cur=cur.next;
        }

        Collections.reverse(list);

        int[] res=new int[list.size()];

        for(int i=0;i<list.size();i++){
            res[i]=list.get(i);
        }

        return res;
    }
}
